<template>
  <!-- <u-tabbar
    :value="value6"
    @change="(name) => (value6 = name)"
    :fixed="true"
    :placeholder="true"
    :safeAreaInsetBottom="true"
  >
    <u-tabbar-item text="首页" icon="home" @click="click1"></u-tabbar-item>
    <u-tabbar-item text="发需求" icon="coupon"></u-tabbar-item>
    <u-tabbar-item text="找项目" icon="integral-fill"></u-tabbar-item>
    <u-tabbar-item
      text="信息中心"
      icon="list-dot"
      @click="click1"
    ></u-tabbar-item>
    <u-tabbar-item text="我的" icon="account" @click="click1"></u-tabbar-item>
  </u-tabbar> -->
  <view>
    <u-tabbar
      :value="value6"
      @change="changeTabbar"
      :fixed="true"
      :placeholder="false"
      :safeAreaInsetBottom="true"
    >
      <u-tabbar-item text="首页" icon="home"></u-tabbar-item>
      <u-tabbar-item text="发需求" icon="coupon"></u-tabbar-item>
      <u-tabbar-item text="商机" icon="integral-fill"></u-tabbar-item>
      <u-tabbar-item text="信息中心" icon="list-dot"></u-tabbar-item>
      <u-tabbar-item text="我的" icon="account"></u-tabbar-item>
    </u-tabbar>
  </view>
</template>

<script setup>
import { ref, defineProps } from "vue";
import { getLoginInfo } from "@/api/userInfo.js";
const value6 = ref(0);
import {
  showToast,
  showLoading,
  hideLoading,
  showModalNoCancel,
} from "@/utils/toast";
const props = defineProps({
  index: {
    type: String,
    default: () => ({}), // 默认值为空对象，避免undefined错误
  },
});
value6.value = props.index;
const changeTabbar = async (e) => {
  console.log(e);
  value6.value = e;
  console.log(value6.value);
  switch (e) {
    case 0:
      uni.reLaunch({
        url: "/pages/index/index",
      });
      break;
    case 1:
      uni.redirectTo({
        url: "/pages_index/demand/index",
      });
      break;
    case 2:
      try {
        let token = null;
        // 尝试从本地存储读取
        token = uni.getStorageSync("token") || null;
        // 如果没有 userinfo，尝试从接口获取
        if (!token) {
          uni.navigateTo({
            url: `/pages/index/search`,
          });
        } else {
          uni.redirectTo({
            url: "/pages_index/user/component/indentList",
          });
        }
      } catch (error) {}

      break;
    case 3:
      // uni.navigateTo({
      // 	url: '/pages/news/newslist'
      // })
      uni.redirectTo({
        url: "/pages_index/news/newslist",
      });
      break;
    case 4:
      uni.redirectTo({
        url: "/pages/user/index",
      });
      break;
  }
};
</script>
<style scoped>
:deep(.u-tabbar__placeholder) {
  display: none !important;
}
</style>
